// inquiry/pages/sense/index.js
const app = getApp()
import {
  HOME,
} from '../../../utils/api';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tipshow: false, //底部提示
    list: [],
    isNew: 'YES',
    page: 1,
    title: '防骗小贴士',
    wxImgUrl: app.globalData.wxImgUrl,
    navBarHeight: '', //头高度
    statusBarHeight: '', //状态栏高度
    num: 8
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //获取头部高度
    let navBarHeightinfo = app.publicFun.navBarHeightinfo()
    this.setData({
      navBarHeight: navBarHeightinfo[0],
      statusBarHeight: navBarHeightinfo[1]
    })
    if (options.id == 1) {
      this.setData({
        title: '急救常识',
        num: 8
      })
    } else {
      this.setData({
        title: '防骗小贴士',
        num: 7
      })
    }
    this.getlist(7)
  },
  //获取数据
  getlist() {
    wx.showLoading({
      title: '正在加载中',
      icon: 'none',
    });
    HOME({
      pageSize: 10,
      pageNum: this.data.page,
      sortType: this.data.isNew == 'YES' ? 'recently' : 'hot',
      categoryId: this.data.num,
    }).then(res => {
      const {
        records,
        total
      } = res;
      if (this.data.page > 1) {
        this.data.list = this.data.list.concat(records);
      } else {
        this.data.list = records;
      }
      this.setData({
        list: this.data.list,
        isloading: true,
        totals: total,
      });
      wx.hideLoading({
        success: res => {},
      });
    });
  },

  handlerInfo(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/detail/index?id=${id}`,
    });
  },

  back() {
    wx.navigateBack({})
  },

  onReachBottom: function () {
    if (this.data.isloading && this.data.list.length < this.data.totals) {
      this.data.page++;
      this.setData({
        isloading: false,
        tipshow: true,
        page: this.data.page,
      });
      this.getlist();
    }
  },

  // onShareAppMessage: function () {
  //   return {
  //     title: '不贪，不恋，不上当。不信，不听，不转账'
  //   }
  // }
})